package com.ophiux.utils.common;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @desc：正则表达式验证工具<br>
 * @author: hhl<br>
 * @date: 2021年9月3日 上午9:39:56<br>
 */
public class RegularUtils {

	public static enum Regulars {
		/**
		 * 验证手机号码
		 */
		MobileNo("^(1[0-9])\\d{9}$"),
		/**
		 * 验证数字
		 */
		Number("^(-?[1-9]\\d*\\.?\\d*)|(-?0\\.\\d*[1-9])|(-?[0])|(-?[0]\\.\\d*)$"),
		/**
		 * 验证金额
		 */
		money("^(([1-9]{1}\\d*)|([0]{1}))(\\.(\\d){0,2})?$");

		private String Pattern;

		public String getPattern() {
			return Pattern;
		}

		private Regulars(String pattern) {
			Pattern = pattern;
		}

	}

	private static RegularUtils istance;

	/**
	 * 获取单利模式操作对象
	 * 
	 * @return
	 */
	public static RegularUtils getIstance() {
		return (istance == null) ? (istance = new RegularUtils()) : istance;
	}

	private RegularUtils() {
	}

	/**
	 * 
	 * 描述 :验证指定 格式</br>
	 * @param MobileNo
	 * @return
	 */
	public boolean IsValidMobileNo(String MobileNo) {
		Pattern pattern = Pattern.compile(Regulars.MobileNo.getPattern());
		Matcher matcher = pattern.matcher(MobileNo);
		return matcher.matches();
	}

	/**
	 * 
	 * 描述 :正则表达式验证 公共方法</br>
	 * @param input
	 * @param regex
	 * @return
	 */
	public boolean isMatches(CharSequence input, Regulars regex) {
		return Pattern.matches(regex.getPattern(), input);
	}

	public static void main(String[] args) {
		System.out.println(RegularUtils.getIstance().isMatches("22.11.22", RegularUtils.Regulars.money));
	}

}
